<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>像素宽度props</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <my-com :width="width"></my-com>
        <input type="text" v-model="width">
    </div>

    <template id="temp">
        '<div :style="style" style="background-color: yellow;">组件内容宽度{{ width }}px，背景颜色为黄色。</div>'
    </template>

    <!-- <div style="background-color: yellow;">组件内容宽度100px，背景颜色为黄色。</div> -->

    <script type="text/javascript">
        Vue.component('my-com', {
            // ... 选项 ...
            props: ['width'],
            template: '#temp',
            computed: {
                style: function () {
                    return {
                        width: this.width + 'px'
                    }
                }
            }
        });

        var app = new Vue({
            el: '#app',
            data: {
                width: 120
            }
        });
    </script>
</body>

</html>